// LoadTLB.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


//#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \
//        DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)
//DEFINE_GUID(IID_BoFormObjectEnum,0x52D5D04F,0x658C,0x475f,0xA8,0x8C,0x86,0x8B,0x66,0xCD,0x6A,0x59);
//typedef /* [uuid] */  DECLSPEC_UUID("52D5D04F-658C-475f-A88C-868B66CD6A59") 
//enum BoFormObjectEnum
//    {	fo_None	= -1,
//	fo_UserDefinedObject	= 0,
//	fo_GLAccounts	= 1,
//	fo_BusinessPartner	= 2,
//	fo_Items	= 4 
//	 
//    } 	BoFormObjectEnum;
extern "C" const GUID __declspec(selectany) IID_BoFormObjectEnum = { 0x52D5D04F, 0x658C, 0x475f, { 0xA8, 0x8C, 0x86, 0x8B, 0x66, 0xCD, 0x6A, 0x59 } };


int _tmain(int argc, _TCHAR* argv[])
{
	CoInitialize(NULL);
	SetCurrentDirectoryW(L"C:\\Users\\i069498\\B1\\local\\B1\\Client_890.001.01_1148156_HANA_COR\\Client");


	std::set<int> values;
	std::set<std::wstring> names;
	ITypeLib* pTypeLib = NULL;
	ITypeInfo* pTypeInfo = NULL;
	TYPEATTR* pTypeAttr = NULL;
	HRESULT hr;

	hr = LoadTypeLibEx(L"SAPbouiCOM.exe", REGKIND::REGKIND_NONE, &pTypeLib);
	if(FAILED(hr))
	{
		printf("Failure calling LoadTypeLibEx()\n");
		return -1;
	}

	hr = pTypeLib->GetTypeInfoOfGuid(IID_BoFormObjectEnum, &pTypeInfo);
	if(FAILED(hr))
	{
		printf("Failure calling ITypeLib::GetTypeInfoOfGuid()\n");
		return -1;
	}

	hr = pTypeInfo->GetTypeAttr(&pTypeAttr);
	if(FAILED(hr))
	{
		printf("Failure calling ITypeInfo::GetTypeAttr()\n");
		return -1;
	}

	if(pTypeAttr->typekind != TYPEKIND::TKIND_ENUM)
	{
		printf("TYPEATTR::typekind does not equal to TKIND_ENUM\n");
		return -1;
	}

	for (int i = 0; i < pTypeAttr->cVars; i++)
	{
		VARDESC* pVarDesc = NULL;
		hr = pTypeInfo->GetVarDesc(i, &pVarDesc);
		if(FAILED(hr))
		{
			printf("Failure calling ITypeInfo::GetVarDesc(%d)\n", i);
			return -1;
		}

		//names.insert(pVarDesc->lpstrSchema);
		values.insert(pVarDesc->lpvarValue->lVal);
	}

	bool flag = values.find(0) != values.cend();
	bool flag2 = values.find(39) != values.cend();
	

	pTypeInfo->Release();
	pTypeLib->Release();
	CoUninitialize();
	return 0;
}

